import {Injectable} from '@angular/core';
import {Auth} from "../core/foundations/Auth";
import {Http} from "@angular/http";
import {Employee} from "../models/Employee";
import {url_employee as URL} from "../config";

/*
 Generated class for the CustomerAuthProvider provider.

 See https://angular.io/docs/ts/latest/guide/dependency-injection.html
 for more info on providers and Angular 2 DI.
 */
@Injectable()
export class EmployeeProvider extends Auth {

  userDataKey = 'employee_info';
  usernameKey = 'employee_name';
  emailKey = 'employee_email';

  constructor(public http: Http) {
    super();
    this.apiUrl = URL;
  }


  userInfo(): Employee | null {
    return JSON.parse(super.userInfo()) as Employee;
  }

  apiToken(user?: Employee): string | null {
    if (user != null) {
      return user.api_token;
    }
    if (this.check())
      return localStorage.getItem(this.apiTokenKey);
  }

  username(user?: Employee): string | null {
    if (user != null) {
      return user.Employee_Name;
    }
    if (this.check())
      return localStorage.getItem(this.usernameKey);
  }

  email(user?: Employee): string | null {
    if (user != null) {
      return user.Employee_Email;
    }
    if (this.check())
      return localStorage.getItem(this.emailKey);
  }

  store(store_id: string): string | null {
    if (store_id != null)
      localStorage.setItem("Store_ID", store_id);
    return localStorage.getItem("Store_ID");
  }


}
